<?php
/**
 * Auther: Joshua Conero
 * Date: 2017/7/9 0009 8:23
 * Email: brximl@163.com
 * Name: 首页
 */

namespace App\Http\Controllers\Index;


use App\Http\Controllers\Controller;
use App\Models\User;
use hyang\Util;

class Home extends Controller
{
    public function Action($user=null){
        $result = request()->get('result');
        $isLogin = false;
        $userNoHas = false;
        if($result){
            $userInfo = $this->getUserInfo($result,true);
            if(isset($userInfo['user'])){
                $user = $userInfo['user'];
                $isLogin = true;
            }
        }elseif (empty($user)) {
            $user = $this->getUserInfo('user');
            if($user) $isLogin = true;
        }elseif ($user){
            if($user == $this->getUserInfo('user')) $isLogin = true;
            else{
                //$
                $userMd = new User();
                if(!$userMd->UserExist($user)) $userNoHas = true;
            }
        }

        $data = $this->pageInit([
            'title' => $user? ($isLogin? '【'.$user.'】欢饮您': $user.' - Aurora' ): '用户中心'
            ,'css'    => 'index/home'
        ]);

        // 前端数据传递
        $this->jsVar([
            'user' => $user? $user:'',
            'isLogin' => $isLogin? 'Y':'N',
            'illuser' => $userNoHas? 'Y':'N'
        ]);
        $this->crtJsVarScpt($data);
        return view('index.home', $data);
    }
}